﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentApartMentManage
{
    public partial class DMR : Form
    {
       
        public DMR()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && e.ColumnIndex > -1 && e.RowIndex > -1)
            {
                //右键选中单元格
                dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;

                //在单元格处弹出菜单
                contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
            }
        }

        private void DMR_Load(object sender, EventArgs e)
        {
           
            dataGridView1.DataSource = DataShow.show("select 公寓楼号,公寓号,维修项目 from 公寓维修管理表");
        }

        private void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
        {
            
        }

        private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox3.Text.Length>255)
            {
                MessageBox.Show("维修项目超过255个字符,请重新输入!");
                return;
            }
            try
            {
                if(MessageBox.Show("确定要登记吗?","提示",MessageBoxButtons.YesNo)==DialogResult.Yes)
                {
                    string sql = string.Format("insert into 公寓维修管理表(公寓楼号,公寓号,维修项目) values('{0}','{1}','{2}')", textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text);
                    int i = sqlHelper.Execute(sql);
                    if (i != -1)
                    {
                        MessageBox.Show("信息登记成功!");

                    }
                    else
                        MessageBox.Show("信息登记失败!");
                }
            }catch(Exception ex)
            {
                MessageBox.Show("登记失败!");
                return;
            }
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = DataShow.show("select 公寓楼号,公寓号,维修项目 from 公寓维修管理表");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("你真的要清空输入的信息吗","提示",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
